//
//  UILabel+Helper.m
//  ketuitui
//
//  Created by apple on 14-10-25.
//  Copyright (c) 2014年 LAURA. All rights reserved.
//
#import "UILabel+Helper.h"
#import "UIView+Helper.h"
//#import "NSString+sizeToFit.h"
@implementation UILabel (Helper)

//add text left Label
+(UILabel *) addTextLeftLabelWithText: (NSString *) text font: (UIFont *) font textColor: (UIColor *) textColor backGroundColor: (UIColor *) backGroundColor frame: (CGRect) frame{
    UILabel *label = [[UILabel alloc] initWithFrame: frame];
    label.font = font;
    label.text = text;
    label.textColor = textColor;
    label.backgroundColor = backGroundColor;
    label.numberOfLines = 0;
    return label;
}

//add text right Label
+(UILabel *) addTextRightLabelWithText: (NSString *) text font: (UIFont *) font textColor: (UIColor *) textColor backGroundColor: (UIColor *) backGroundColor frame: (CGRect) frame{
    UILabel *label = [[UILabel alloc] initWithFrame: frame];
    label.font = font;
    label.text = text;
    label.textColor = textColor;
    label.backgroundColor = backGroundColor;
    label.textAlignment = NSTextAlignmentRight;
    return label;
}

//根据文字确定Label大小
+(UILabel *) addAdjustLabelWithText: (NSString *) text font: (UIFont *) font textColor: (UIColor *) textColor backGroundColor: (UIColor *) backGroundColor originX: (float) originX originY: (float) originY{
    CGSize expectSize = [text sizeWithAttributes:@{
                                                   NSFontAttributeName : font
                                                   }];
    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake( originX , originY , expectSize.width , expectSize.height )];
    label.font = font;
    label.text = text;
    label.textColor = textColor;
    label.backgroundColor = backGroundColor;
    label.numberOfLines = 0;
    return label;
}

////根据文字确定居中Label大小
//+(UILabel *) addCenterLabelWithText: (NSString *) text font: (UIFont *) font textColor: (UIColor *) textColor backGroundColor: (UIColor *) backGroundColor originY: (float) originY originX: (float) originX{
//    
//    CGSize frame = CGSizeMake( CGRectGetWidth( [[UIScreen mainScreen] bounds] ) / 2 * originX , CGRectGetHeight( [UIScreen mainScreen].applicationFrame ) * 1000 );
//
//    CGSize expectSize = [text boundingSizeWithSize:frame
//                                         attribute:@{
//                                                     NSFontAttributeName : font
//                                                     }];
//
//    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake( CGRectGetWidth( [[UIScreen mainScreen] bounds] ) / 2 - expectSize.width / 2 , originY , expectSize.width , expectSize.height )];
//    label.font = font;
//    label.text = text;
//    label.textColor = textColor;
//    label.numberOfLines = 0;
//    label.backgroundColor = backGroundColor;
//    return label;
//}

//给一个起始点 然后 根据文字大小 居中Label
+(UILabel *) XaddLabelWithText: (NSString *) text font: (UIFont *) font textColor: (UIColor *) textColor backGroundColor: (UIColor *) backGroundColor textBeginRect: (CGRect) textBeginRect{
    if (text.length == 0){
        return nil;
    }
    UILabel *label = [[UILabel alloc] initWithFrame: textBeginRect];
    label.text = text;
    label.font = font;
    label.textColor = textColor;
    label.backgroundColor = backGroundColor;
    NSDictionary *attributes = @{NSFontAttributeName : font};
    CGFloat with = [[[NSAttributedString alloc] initWithString: text attributes: attributes] size].width;
    CGRect rect = CGRectMake( textBeginRect.origin.x , textBeginRect.origin.y , with , font.pointSize );
    label.frame = rect;
    return label;
}

//文字居中Label
+(UILabel *) addTextCenterLabelWithText: (NSString *) text font: (UIFont *) font textColor: (UIColor *) textColor backGroundColor: (UIColor *) backGroundColor frame: (CGRect) frame{
    UILabel *label = [[UILabel alloc] initWithFrame: frame];
    label.font = font;
    label.text = text;
    label.textColor = textColor;
    label.backgroundColor = backGroundColor;
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 0;
    return label;
}

+(UILabel *) XaddLineLabel: (UIColor *) lineColor frame: (CGRect) frame{
    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake( frame.origin.x , frame.origin.y , frame.size.width , frame.size.height )];
    label.backgroundColor = lineColor;
    return label;
}

//左右两行字分别靠近左右
+(UILabel *) addLabelRightLabelFrame: (CGRect) frame rightTextFont: (int) rightFont rightTextColor: (UIColor *) rightTextColor leftTextFont: (int) leftTextFont leftTextColor: (UIColor *) leftTextColor LabelbackGroundColor: (UIColor *) backGroundColor rightTextTitle: (NSString *) rightTextTitle leftTextTitle: (NSString *) leftTextTitle{

    UILabel *label = [[UILabel alloc] initWithFrame: frame];
    label.backgroundColor = backGroundColor;

    UILabel *leftlabel = [UILabel addAdjustLabelWithText: leftTextTitle font: [UIFont systemFontOfSize: leftTextFont] textColor: leftTextColor backGroundColor: [UIColor clearColor] originX: 0 originY: frame.size.height / 2];
    leftlabel.textAlignment = NSTextAlignmentLeft;

    UILabel *rightLabel = [UILabel addAdjustLabelWithText: rightTextTitle font: [UIFont systemFontOfSize: rightFont] textColor: rightTextColor backGroundColor: [UIColor clearColor] originX: leftlabel.maxX originY: frame.size.height / 2];
    rightLabel.textAlignment = NSTextAlignmentRight;
    [label addSubview: leftlabel];
    [label addSubview: rightLabel];

    return label;
}
@end
